﻿using System;
using System.IO;

namespace NumericalSolution {
  class Diffusion1DMain {

    static String outfile = "c:/nsworkspace/exact.txt";

    static void Main(string[] args) {

      Diffusion1D sim = new Diffusion1DExact();

      sim.NumberOfNodes = 11;
      sim.DeltaTime = 0.005;
      sim.EndTime = 1.0;

      double[] u;
      StreamWriter writer = File.CreateText(outfile);

      for (sim.CurrentTime = 0.0;
           sim.CurrentTime <= sim.EndTime;
           sim.CurrentTime += sim.DeltaTime) {

        if (sim.CurrentTime == 0.0) {
          u = sim.Initialize();
        } else {
          u = sim.Next();
        }

        for (int i = 0; i < u.Length; i++) {
          writer.Write(sim.CurrentTime + " ");
          writer.Write(sim.DeltaX * i + " ");
          writer.WriteLine(u[i]);
        }
        writer.WriteLine();
      }
      writer.Close();
    }
  }
}
